<template>
	<!-- 系统消息 -->
	<view class="">
		<view v-if="list.length <= 0" class="p-2 mt-3" style="margin: 100rpx auto;">
			<u-empty mode="data" icon="http://cdn.uviewui.com/uview/empty/data.png" text="暂无消息"></u-empty>
		</view>
		<view class="" v-for="(list_item, idx) of list" :key="idx">
			<view class="mb-2" v-for="(item, index) of list_item" :key="item.id">
				<u-swipe-action :autoClose="actionShow">
					<u-swipe-action-item :options="options1" :index="index" @click="delet(item, index, list_item)">
						<view class="swipe-action">
							<view class="bg-white p-3 2 flex justify-between align-center" @click="toDetail(item)">
								<view class="" style="width: 80%;">
									<view class="font-sm c_9 mt-1" v-if="item.source">{{ item.source }}</view>
									<view class="font-sm c_6 mt-1">{{ item.content }}</view>
									<view class="font_24 c_9 my-1">{{ dataTime(item.create_at) }}</view>
								</view>
								<view class="flex flex-column justify-center align-center" style="width: 20%;">
									<view v-if="item.status == 0"><u-badge :isDot="true" type="error"></u-badge></view>
									<view class="mt-3" v-if="(type == 1 && item.type_code == 1) || type == 4">
										<u-tag v-if="item.examine_status == 0" text="申请中" plain size="mini"></u-tag>
										<u-tag v-else-if="item.examine_status == 1" text="已同意" type="success" plain
											size="mini"></u-tag>
										<u-tag v-else-if="item.examine_status == 2" text="已拒绝" type="error" plain
											size="mini"></u-tag>
									</view>
								</view>
							</view>
						</view>
					</u-swipe-action-item>
				</u-swipe-action>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		messageList,
		messageDelete
	} from '@/api/my/inform.js';
	import util from '@/common/js/util.js';
	export default {
		data() {
			return {
				list: [],
				tit: '',
				options1: [{
					text: '删除',
					style: {
						backgroundColor: '#CF1526',
						marginLeft: '30rpx'
					}
				}],
				type: '',
				actionShow: false
			};
		},
		computed: {
			dataTime(val) {
				return function(val) {
					return util.getDateBeforeNow(val);
				};
			}
		},
		onLoad(option) {
			this.type = option.type;
			// this.getInfo();
			uni.setNavigationBarTitle({
				title: option.title
			});
			// 分享
			wx.showShareMenu({
				withShareTicket: true,
				menus: ['shareAppMessage', 'shareTimeline']
			});
		},
		onShow() {
			this.getInfo();
		},
		methods: {
			getInfo() {
				let msg = {
					type: this.type,
					token: uni.getStorageSync('userInfo').token || ''
				};
				messageList(msg)
					.then(res => {
						if (res.code == 0) {
							this.list = res.data.list;
							this.tit = res.data.title;
						} else {
							uni.$u.toast(res.msg);
						}
					})
					.catch(err => {
						console.log('获取系统失败', err);
					});
			},
			toDetail(val) {
				uni.navigateTo({
					url: './detail?id=' + val.id + '&title=' + this.tit
				});
			},
			delet(val, idx, array) {
				let msg = {
					id: val.id,
					token: uni.getStorageSync('userInfo').token || ''
				};
				messageDelete(msg)
					.then(res => {
						uni.$u.toast(res.msg);
						if (res.code == 0) {
							array.splice(idx, 1);
							this.actionShow = true;
							// this.getInfo();
						}
					})
					.catch(err => {
						console.log('删除消息失败', err);
					});
			}
		}
	};
</script>

<style lang="scss" scoped></style>